//
//  cancelConsultView.m
//  one_mile_01
//
//  Created by 王进帅 on 15/9/16.
//  Copyright (c) 2015年 王雅蓉. All rights reserved.
//

#import "cancelConsultView.h"

@implementation cancelConsultView

-(instancetype)initWithFrame:(CGRect)frame{
    if (self = [super initWithFrame:frame]) {
        
        [self creatcancelConsultSubView];
    }
    return  self;
}

-(void)creatcancelConsultSubView{
    
    UIView *settingView = [[UIView alloc] initWithFrame:CGRectMake(50 * FITRATE, 150 * FITRATE, WIDTH - 100 * FITRATE, 200 * FITRATE)];
    settingView.layer.masksToBounds = YES;
    settingView.layer.cornerRadius = 15.0f;
    settingView.backgroundColor = [UIColor whiteColor];
    [self addSubview:settingView];
  
    
    UILabel *cancelLabel = [[UILabel alloc]initWithFrame:CGRectMake(10, 40 * FITRATE, settingView.frame.size.width - 20, 30 * FITRATE)];
    cancelLabel.text = @"确定取消咨询吗？";
    cancelLabel.textAlignment = NSTextAlignmentCenter;
    cancelLabel.font = [UIFont systemFontOfSize:20 * FITRATE];
    [settingView addSubview:cancelLabel];
    
    //    取消
    UIButton *cancelButton = [UIButton buttonWithType:UIButtonTypeCustom];
    [settingView addSubview:cancelButton];
    [cancelButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.bottom.equalTo(settingView.mas_bottom).offset(-20 * FITRATE);
        make.left.equalTo(settingView.mas_left).offset(15 * FITRATE);
        make.right.equalTo(settingView.mas_right).offset(-(settingView.frame.size.width - 15 - 60 - 30 * FITRATE));
        make.top.equalTo(settingView.mas_top).offset(settingView.frame.size.height - 30 * FITRATE - 20);
    }];
    cancelButton.backgroundColor = [UIColor lightGrayColor];
    cancelButton.layer.masksToBounds = YES;
    cancelButton.layer.cornerRadius = 15 * FITRATE;
    [cancelButton setTitle:@"取消" forState:UIControlStateNormal];
    [cancelButton addTarget:self action:@selector(cancelButtonAction) forControlEvents:UIControlEventTouchUpInside];
    
    //    确定
    UIButton *agreeButton = [UIButton buttonWithType:UIButtonTypeCustom];
    [settingView addSubview:agreeButton];
    [agreeButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.bottom.equalTo(settingView.mas_bottom).offset(-20 * FITRATE);
        make.left.equalTo(settingView.mas_left).offset(settingView.frame.size.width - 15 - 30 * FITRATE - 60);
        make.right.equalTo(settingView.mas_right).offset(- 15 * FITRATE);
        make.top.equalTo(settingView.mas_top).offset(settingView.frame.size.height - 30 * FITRATE - 20);
    }];
    agreeButton.backgroundColor = [UIColor colorWithRed:71/255.0 green:173/255.0 blue:227/255.0 alpha:1.0];
    agreeButton.layer.masksToBounds = YES;
    agreeButton.layer.cornerRadius = 15 * FITRATE;
    [agreeButton setTitle:@"确认" forState:UIControlStateNormal];
    agreeButton.titleLabel.font = [UIFont systemFontOfSize:17 * FITRATE];
    [agreeButton addTarget:self action:@selector(cancelConsultButtonAction) forControlEvents:UIControlEventTouchUpInside];
}

//取消
-(void)cancelButtonAction{
    
    [self CancelConsult ];
}


//动画弹窗  撤回原来弹窗
-(void)cancelConsultButtonAction{
    
    [self CancelConsult];
    
    [self.myDelegate popFromCancelConsult];
}

- (void)CancelConsult{//时间
    
    [NSTimer scheduledTimerWithTimeInterval:1.0f
                                     target:self
                                   selector:@selector(cancelConsultMethod)
                                   userInfo:nil
                                    repeats:YES];
}


//回收弹窗
-(void)cancelConsultMethod
{
    [UIView animateWithDuration:0.4 delay:0.1 options:UIViewAnimationOptionAllowAnimatedContent animations:^{
        
        self.frame = CGRectMake(0, HEIGHT, WIDTH, HEIGHT);
    } completion:^(BOOL finished) {
        
        
    }];
}

@end
